﻿<%@ Page Language="C#" MasterPageFile="~/Site.master" CodeBehind="Edit.aspx.cs" Inherits="salaEstudosEdukanteUsuario.Edit" %>


<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:DynamicDataManager ID="DynamicDataManager1" runat="server" AutoLoadForeignKeys="true" />

    <h2>Modificar dados do Usuário</h2>

    <asp:ScriptManagerProxy runat="server" ID="ScriptManagerProxy1" />

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
                HeaderText="Lista de erros de validação" />
            <asp:DynamicValidator runat="server" ID="DetailsViewValidator" ControlToValidate="DetailsView1" Display="None" />


            
             <asp:DetailsView ID="DetailsView1" runat="server" 
                DataSourceID="DetailsDataSource" DefaultMode="Edit"
                AutoGenerateEditButton="False" AutoGenerateDeleteButton="False" OnItemCommand="DetailsView1_ItemCommand" 
                OnItemUpdated="DetailsView1_ItemUpdated"
                CssClass="detailstable" FieldHeaderStyle-CssClass="bold" 
                AutoGenerateRows="False">
                <FieldHeaderStyle CssClass="bold" />
                <Fields>
                
                    <asp:DynamicField DataField="nomeUsuario" HeaderText="Nome " />
                    <asp:DynamicField DataField="tipoUsuario" HeaderText="Tipo do usuário " />
                    <asp:DynamicField DataField="emailUsuario" HeaderText="Email " />
<%--                    <asp:DynamicField DataField="senhaUsuario" HeaderText="Senha " />
--%>                    <asp:DynamicField DataField="ativoUsuario" HeaderText="Ativo? " />
                    
                    
                         
                    <asp:TemplateField ShowHeader="False">
                        <EditItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                                CommandName="Update" Text="Alterar" OnClientClick="return validar();"></asp:LinkButton>
                            &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                                CommandName="Cancel" Text="Cancelar"></asp:LinkButton>
                        </EditItemTemplate>
                    </asp:TemplateField>
                </Fields>
            </asp:DetailsView>
            

            <asp:LinqDataSource ID="DetailsDataSource" runat="server" EnableUpdate="true">
                <WhereParameters>
                    <asp:DynamicQueryStringParameter />
                </WhereParameters>
            </asp:LinqDataSource>
            <Script language="javascript">

                function validar() {


                    for (i = 0; i < document.aspnetForm.elements.length; i++) {

                        //localizar o nome do campo de nome do usuário

                        var encontrouDesc = document.aspnetForm.elements[i].name.indexOf("nomeUsuario");

                        if (encontrouDesc >= 0) {

                            //validar

                            if (document.aspnetForm.elements[i].value == "") {

                                alert('O nome deve ser informado.');
                                document.aspnetForm.elements[i].focus();
                                return false;

                                // Fim segundo IF
                            }
                            //Fim primeiro IF
                        }
                        //Fim do FOR 1
                    }

                    for (i = 0; i < document.aspnetForm.elements.length; i++) {

                        //localizar o nome do campo do tipo do usuário (obs: combobox)

                        var encontrouDesc = document.aspnetForm.elements[i].name.indexOf("tipoUsuario");

                        if (encontrouDesc >= 0) {

                            //validar

                            if (document.aspnetForm.elements[i].value == 0) {

                                alert('O tipo do usuário deve ser informado.');
                                document.aspnetForm.elements[i].focus();
                                return false;

                                // Fim segundo IF
                            }
                            //Fim primeiro IF
                        }
                        //Fim do FOR 2
                    }
                    for (i = 0; i < document.aspnetForm.elements.length; i++) {

                        //localizar o nome do campo do email do usuário

                        var encontrouDesc = document.aspnetForm.elements[i].name.indexOf("emailUsuario");

                        if (encontrouDesc >= 0) {

                            //validar

                            if (document.aspnetForm.elements[i].value == "") {

                                alert('O email deve ser informado.');
                                document.aspnetForm.elements[i].focus();
                                return false;

                                // Fim segundo IF
                            } else {
                                return true;
                                // Fim ELSE
                            }
                            //Fim primeiro IF
                        }
                        //Fim do FOR 3
                    }

                    //Fim da função validar  
                }
                // Fim do script
            </script>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
